package com.ithema.b2b.goodsconsumer.service;

import com.ithema.b2b.goodsconsumer.hystrix.GoodsServiceHystrix;
import model.Cart;
import model.Goods;
import model.Userorder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Component
@FeignClient(value = "b2b-goods-provider", fallback = GoodsServiceHystrix.class)
public interface GoodsService {
    @GetMapping(value = "/getAllgoods")
    List<Goods> getAllgoods();

    @GetMapping(value = "/getOnegoods")
    List<Goods> getOnegoods(@RequestParam(value = "gname") String gname);

    @GetMapping(value = "/getOnegid")
    Goods getOnegid(@RequestParam(value = "gid") int gid);

    /**
     * 插入一条购物车记录
     * @param goodsname
     * @param number
     * @param price
     * @param goodsid
     * @param uid
     * @return
     */
    @GetMapping(value = "/insertCart")
    int insertCart(@RequestParam(value = "goodsname")String goodsname,
                   @RequestParam(value = "number")int number,
                   @RequestParam(value = "price")int price,
                   @RequestParam(value = "goodsid")int goodsid,
                   @RequestParam(value = "uid")int uid);

    /**
     * 根据商品ID更新购物车商品数量
     * @param number
     * @param id
     * @return
     */
    @GetMapping(value = "/updateCart")
    int updateCart(@RequestParam(value = "number")int number,
                   @RequestParam(value = "id")int id);

    /**
     * 获取当前用户的所有购物车商品记录
     * @param uid
     * @return
     */
    @GetMapping(value = "/getAllCart")
    List<Cart> getAllCart(@RequestParam(value = "uid")int uid);


    @GetMapping(value = "/deleteCart")
    int deleteCart(@RequestParam(value = "did")int did);

    @GetMapping("/getAllorder")
    List<Userorder> getAllorder(@RequestParam(value = "uid")int uid);

    @GetMapping(value = "/insertOrder")
    int insertOrder(@RequestParam(value = "goodsname")String goodsname,
                    @RequestParam(value = "number")int number,
                    @RequestParam(value = "price")int price,
                    @RequestParam(value = "uid")int uid);
}
